//获取滚动条的滚动距离
function getScrollOffset(){
    if(window.pageXOffset){
        return{
            x : window.pageXOffset,
            y : window.pageYOffset
        }
    }else{
        return{
            x : document.body.scrollLeft + document.documentElement.scrollLeft,
            y : document.body.scrollTop + document.documentElement.scrollTop
        }
    }
}
//查看视口的尺寸
function getViewportOffset(){
    if(window.innerWidth){
        return{
            width : window.innerWidth,
            height : window.innerHeight
        }
    }else{
        if(document.compatMode === 'BackCopat'){
            return{
                width : document.body.clientWidth,
                height : document.body.clientHeight
            }
        }else{
            return{
                width : document.documentElement.clientWidth,
                height : document.documentElement.clientHeigeht
            }
        }
    }
}
//查询样式
function getStyle(elem, prop){
    if(window.getComputedStyle){
        return window.getComputedStyle(elem,null)[prop];
    }else{
        return elem.currentStyle[prop];
    }
}
//获取鼠标点坐标
function pagePos(e) {
	var sLeft = getScrollOffset().left,
		sTop = getScrollOffset().top,
		cLeft = document.documentElement.clientLeft || 0,
	//获取文档偏移量，文档偏移量不存在时，值为undefined，值为undefined就取0
		cTop = document.documentElement.clientTop || 0;
	return {
		X: e.clientX + sLeft - cLeft,
		Y: e.clientY + sTop - cTop
	}

}
//绑定事件处理函数
function addEvent(elem, type, fn){
    if(elem.addEventListener){
        elem.addEventListener(type, fn, false);
    }else if(elem.attachEvent){
        elem.attachEvent('on' + type , function(){
            fn.call(elem); //解决this指向window
        })
    }else{
        elem['on' + type] = fn;
    }
}
//解除事情处理
function removeEvent(elem, type, fn){
    if(elem.addEventListener){
        elem.addEventListener(type, fn, false);
    }else if(elem.attachEvent){
        elem.detachEvent('on' + type, fn);
    }else{
        elem['on' + type] = null;
    }
}
//取消事件冒泡
function stopBubble(event){
    if(event.stopPropagation){
        event.stopPropagation();
    }else{
        event.canceBubble = true;
    }
}
//阻止默认事件
function cancelHandler(event){
    if(event.preventDefault){
        event.preventDefault();
    }else{
        event.returnValue = false;
    }
}